WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
map_base.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
21// Fwd refs
22namespace wolf
23{
24class Problem;
25} // namespace wolf
26
27// Wolf includes
28#include "core/common/wolf.h"
33
34// other includes
35#include "yaml-schema-cpp/yaml_server.hpp"
36
37namespace wolf
38{
39/*
40 * Macro for defining Autoconf map creator.
41 *
42 * Place a call to this macro inside your class declaration (in the map_class.h file),
43 * preferably just after the constructors. Inside 'public' keyword.
44 *
45 * In order to use this macro, the derived map class, MapClass,
46 * must have a constructor available with the API:
47 *
48 * MapClass(const YAML::Node& _params);
49 *
50 * Also, there should be the schema file 'MapClass.schema' containing the specifications
51 * of the user input yaml file.
52 *
53 * NOTE: We use `new` and not `make_shared` since the constructor may (should) be private/protected
54 */
55#define WOLF_MAP_CREATE(MapClass) \
56 static MapBasePtr create(const YAML::Node& _input_node, const std::vector<std::string>& _folders_schema = {}) \
57 { \
58 MapBasePtr map; \
59 if (not _folders_schema.empty()) \
60 { \
61 auto server = yaml_schema_cpp::YamlServer(_folders_schema); \
62 server.setYaml(_input_node); \
63 if (not server.applySchema(#MapClass)) \
64 { \
65 WOLF_ERROR(server.getLog()); \
66 return nullptr; \
67 } \
68 map = std::shared_ptr<MapClass>(new MapClass(server.getNode())); \
69 } \
70 else \
71 map = std::shared_ptr<MapClass>(new MapClass(_input_node)); \
72 if (_input_node["landmarks"]) \
73 { \
74 for (unsigned int i = 0; i < _input_node["landmarks"].size(); i++) \
75 { \
76 LandmarkBasePtr lmk_ptr = \
77 FactoryLandmark::create(_input_node["landmarks"][i]["type"].as<std::string>(), \
78 _input_node["landmarks"][i], \
79 _folders_schema); \
80 lmk_ptr->link(map); \
81 } \
82 } \
83 return map; \
84 } \
85 static MapBasePtr create(const std::string& _yaml_filepath, const std::vector<std::string>& _folders_schema) \
86 { \
87 auto server = yaml_schema_cpp::YamlServer(_folders_schema, _yaml_filepath); \
88 if (not server.applySchema(#MapClass)) \
89 { \
90 WOLF_ERROR(server.getLog()); \
91 return nullptr; \
92 } \
93 return create(server.getNode(), {}); \
94 }
95
96// class MapBase
97class MapBase : public NodeBase, public std::enable_shared_from_this<MapBase>
98{
99 friend LandmarkBase;
100
101 private:
102 LandmarkBasePtrList landmark_list_;
103
104 protected:
105 MapBase();
106 MapBase(const YAML::Node& _params);
107 MapBase(const std::string& _type, const YAML::Node& _params);
108
109 public:
111
112 ~MapBase() override = default;
113 bool hasChildren() const override;
114
115 protected:
116 virtual LandmarkBasePtr addLandmark(LandmarkBasePtr _landmark_ptr);
117 virtual void removeLandmark(LandmarkBasePtr _landmark_ptr);
118
119 public:
120 LandmarkBaseConstPtrList getLandmarkList() const;
121 LandmarkBasePtrList getLandmarkList();
122 LandmarkBaseConstPtr getLandmark(const unsigned int& _id) const;
123 LandmarkBasePtr getLandmark(const unsigned int& _id);
124
125 virtual void load(std::string _map_file_yaml);
126 virtual bool save(std::string _map_file_yaml, const std::string& _map_name = "") const;
127
128 virtual void printHeader(int depth, //
129 bool factored_by, //
130 bool metric, //
131 bool state_blocks,
132 std::ostream& stream,
133 std::string _tabs = "") const;
134 virtual void print(int depth, //
135 bool factored_by, //
136 bool metric, //
137 bool state_blocks,
138 std::ostream& stream = std::cout,
139 std::string _tabs = "") const;
140
141 virtual CheckLog localCheck(bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
142 virtual bool check(CheckLog& _log, bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
143};
144
145inline LandmarkBaseConstPtrList MapBase::getLandmarkList() const
146{
147 LandmarkBaseConstPtrList list_const;
148 for (auto&& obj_ptr : landmark_list_) list_const.push_back(obj_ptr);
149 return list_const;
150}
151
152inline LandmarkBasePtrList MapBase::getLandmarkList()
153{
154 return landmark_list_;
155}
156
157} // namespace wolf
Definition: check_log.h:28
Definition: landmark_base.h:92
Definition: map_base.h:98
virtual bool check(CheckLog &_log, bool _verbose, std::ostream &_stream, std::string _tabs="") const
Definition: map_base.cpp:167
~MapBase() override=default
MapBase()
Definition: map_base.cpp:29
virtual void print(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream=std::cout, std::string _tabs="") const
Definition: map_base.cpp:139
virtual bool save(std::string _map_file_yaml, const std::string &_map_name="") const
Definition: map_base.cpp:91
virtual CheckLog localCheck(bool _verbose, std::ostream &_stream, std::string _tabs="") const
Definition: map_base.cpp:152
virtual void printHeader(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream, std::string _tabs="") const
Definition: map_base.cpp:128
LandmarkBaseConstPtr getLandmark(const unsigned int &_id) const
Definition: map_base.cpp:51
WOLF_MAP_CREATE(MapBase)
LandmarkBaseConstPtrList getLandmarkList() const
Definition: map_base.h:145
virtual LandmarkBasePtr addLandmark(LandmarkBasePtr _landmark_ptr)
Definition: map_base.cpp:40
virtual void removeLandmark(LandmarkBasePtr _landmark_ptr)
Definition: map_base.cpp:46
bool hasChildren() const override
Definition: map_base.cpp:35
virtual void load(std::string _map_file_yaml)
Definition: map_base.cpp:69
Base class for Nodes.
Definition: node_base.h:74
Definition: capture_base.h:23